package com.company.indicationshots.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.appcompat.widget.AppCompatTextView;
//设置页面文字描蓝边
public class SettingStrokeTextView extends AppCompatTextView {
    private Paint outlinePaint;
    private float strokeWidth;

    public SettingStrokeTextView(Context context) {
        super(context);
        init();
    }

    public SettingStrokeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public SettingStrokeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        strokeWidth = 1; // 描边宽度
        outlinePaint = new Paint(getPaint());
        outlinePaint.setStyle(Paint.Style.STROKE);
        outlinePaint.setStrokeWidth(strokeWidth);
        outlinePaint.setAntiAlias(true);
        outlinePaint.setColor(Color.BLUE); // 描边颜色
    }

    @Override
    protected void onDraw(Canvas canvas) {
        // 先绘制描边文本
        canvas.drawText(getText().toString(), getCompoundPaddingLeft(), getBaseline(), outlinePaint);

        // 再绘制填充文本
        super.onDraw(canvas);
    }
}
